import logging

from config import URL
from config import init_log_config


class RechargeApi(object):
    def __init__(self, session):
        self.session = session

    def get_recharge_verify_code(self, r):
        url = URL + "/common/public/verifycode/{}".format(r)
        response = self.session.get(url=url)
        print("获取充值验证码接口返回的状态码:{}".format(response.status_code))
        logging.info("获取充值验证码接口返回的状态码:{}".format(response.status_code))
        return response

    def recharge(self, amount_v,valicode_v,paymentType_v="chinapnrTrust",formStr_v="reForm" ):
        url = URL + "/trust/trust/recharge"
        form_dict = {'paymentType': paymentType_v, "amount": amount_v, 'formStr': formStr_v, 'valicode': valicode_v}
        response = self.session.post(url=url, data=form_dict)
        logging.info("充值接口返回的响应数据:{}".format(response.json()))
        return response

    def third_recharge(self, url, form_dict):
        response = self.session.post(url=url, data=form_dict)
        # 将响应体的数据打印到日志
        logging.info("第三方充值接口的响应体数据:{}".format(response.text))
        # 封装方法的返回
        return response
